<template>
  <el-card>
  <div>
    <!-- 面包屑导航条 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/cusOrder' }">我的订单</el-breadcrumb-item>
      <el-breadcrumb-item>发票中心</el-breadcrumb-item>
      <el-breadcrumb-item>发票管理</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card class="box-card">


      <el-table
        :data="invoiceList"
        stripe
        style="width: 100%">


        <el-table-column
          label="收件人"
          prop="receiver"
          >
        </el-table-column>
        <el-table-column
          label="电话"
          prop="tel"
          >
        </el-table-column>

        <el-table-column
          label="状态"
         >
          <template slot-scope="scope">
            {{scope.row.state|stateFit}}
          </template>
        </el-table-column>
        <el-table-column
          label="收件地址"
          prop="revAddress" >
        </el-table-column>

        <el-table-column
          label="物流公司"
          prop="logisticsCym" >
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          >
          <template slot-scope="scope">
            <el-dropdown>
              <span class="el-dropdown-link">
                <i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">

                <el-button type="primary" v-if="scope.row.state==0" :style="{display:yin}" @click="commitOrders1(scope.row.id)">提交</el-button>
                <el-button type="primary" v-if="scope.row.state==0" :style="{display:yin}" @click="update(scope.row.id)">修改</el-button>
                <el-button type="primary" v-if="scope.row.state==1" :style="{display:yinCang}" @click="commitOrders6(scope.row.id)">通过</el-button>
                <el-button type="primary" v-if="scope.row.state==2" :style="{display:yinCang}" @click="commitOrders2(scope.row.id)">邮寄</el-button>
                <el-button type="primary" v-if="scope.row.state==1" :style="{display:yinCang}" @click="commitOrders3(scope.row.id)">拒绝</el-button>
                <el-button type="primary" v-if="scope.row.state==4" :style="{display:yin}" @click="commitOrders7(scope.row.id)">签收</el-button>
                <el-button type="primary" @click="orderRecord(scope.row.id)">发票记录</el-button>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>


      </el-table>

      <el-dialog title="不通过描述" :visible.sync="dialogFormVisible">
        <el-form :model="invoiceLog">
          <el-form-item label="描述" >
            <el-input v-model="invoiceLog.remarks" autocomplete="off"></el-input>
          </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="commitOrders4()">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog title="物流信息" :visible.sync="dialogFormVisible1">
        <el-form :model="logisticsCym" >
          <el-form-item label="物流公司" >
            <el-input v-model="logisticsCym" autocomplete="off"></el-input>
          </el-form-item>

        </el-form>
        <el-form :model="code" >
          <el-form-item label="物流单号" >
            <el-input v-model="code" autocomplete="off"></el-input>
          </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="commitOrders5()">确 定</el-button>
        </div>
      </el-dialog>
      <el-pagination
        :current-page="page.pagenum"
        :page-size="page.pagesize"
        :page-sizes="[5, 10, 20, 40]"
        :total="total"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>


    </el-card>

  </div>
  </el-card>
</template>

<script>
    export default {
        name: "InvoiceList",
      data(){
          return{
            page:{
              pagenum:0,
              pagesize:5
            },
            total:0,
            invoiceList:[],
            invoiceLog:{},
            dialogFormVisible:false,
            dialogFormVisible1:false,
            code:"",
            logisticsCym:"",
            uid:0,
            cid:0,
            yinCang:"none",
            yin:"none"
          }
      },
      methods:{

          //隐藏
        isShow:function(){

          if(this.uid!=0){
            this.yinCang='';
          }
          if(this.cid!=0){
            this.yin='';
          }
        },
        searchList:function(id){
          this.$http.post("/invoice/list/" + this.page.pagenum + "/" + this.page.pagesize+"/"+id).then((res) => {
            this.invoiceList=res.data.result.list;
            this.total=res.data.result.total;
          })
        },


          //发票记录
        orderRecord:function(id){
          this.$router.push('/invoiceLog?id='+id);
        },

        handleSizeChange: function (val) {
          this.page.pagesize = val;
          this.searchList(this.cid)
        },
        handleCurrentChange: function (val) {
          this.page.pagenum = val;
          this.searchList(this.cid)
        },
        commitOrders1(id){
          this.invoiceLog.invoiceId=id;
          this.invoiceLog.userName=JSON.parse(sessionStorage.getItem("linkman")).name;
          this.invoiceLog.userId=JSON.parse(sessionStorage.getItem("linkman")).id;
          this.$http.post("invoice/find1",this.invoiceLog).then((res)=>{
            this.$message(res.data.message);
          });
          window.location.reload();
        },
        commitOrders6(id){
          this.invoiceLog.invoiceId=id;
          this.invoiceLog.userName=JSON.parse(sessionStorage.getItem("user")).userName;
          this.invoiceLog.userId=JSON.parse(sessionStorage.getItem("user")).id;
          this.$http.post("invoice/find4",this.invoiceLog).then((res)=>{
            this.$message(res.data.message);
          });
          window.location.reload();
        },
        commitOrders7(id){

          this.invoiceLog.invoiceId=id;
          this.invoiceLog.userName=JSON.parse(sessionStorage.getItem("linkman")).name;
          this.invoiceLog.userId=JSON.parse(sessionStorage.getItem("linkman")).id;
          this.$http.post("invoice/find5",this.invoiceLog).then((res)=>{
            this.$message(res.data.message);
          });
          window.location.reload();
        },
        commitOrders2(id){
          this.dialogFormVisible1=true;
          this.invoiceLog.invoiceId=id;
          this.invoiceLog.userName=JSON.parse(sessionStorage.getItem("user")).userName;
          this.invoiceLog.userId=JSON.parse(sessionStorage.getItem("user")).id;

        },
        commitOrders3(id){
          this.dialogFormVisible=true;
          this.invoiceLog.invoiceId=id;
          this.invoiceLog.userName=JSON.parse(sessionStorage.getItem("user")).name;
          this.invoiceLog.userId=JSON.parse(sessionStorage.getItem("user")).id;

        },
        commitOrders4(){
          this.$http.post("invoice/find3/",this.invoiceLog).then((res)=>{
            this.$message(res.data.message);
          });
          this.dialogFormVisible=false;
          this.invoiceLog={};
          window.location.reload();
        },
        commitOrders5(){
          this.$http.post("invoice/find2/"+this.code+"/"+this.logisticsCym,this.invoiceLog).then((res)=>{
            this.$message(res.data.message);
          });
          this.dialogFormVisible=false;
          this.code="";
          this. logisticsCym=""
          window.location.reload();
        },

        update(id){
          this.$router.push("/updateReceipt?id="+id);
        }
      },
      filters:{
          stateFit(val){
            if (val==0){
              return "未提交";
            }
            if (val==1){
              return "提交";
            }
            if (val==2){
              return "审核通过";
            }
            if (val==3){
              return "审核未通过";
            }
            if (val==4){
              return "已邮寄";
            }
            if (val==5){
              return "已签收";
            }

          }
      },
      mounted() {
          var id=0;
          if (sessionStorage.getItem("customer")!=null) {
            id = JSON.parse(sessionStorage.getItem("customer")).id;
          }
            this.searchList(id);




          if(JSON.parse(sessionStorage.getItem("user"))!=null){
            this.uid=JSON.parse(sessionStorage.getItem("user")).id;
          }
          if (sessionStorage.getItem("customer")!=null) {
            this.cid = JSON.parse(sessionStorage.getItem("customer")).id;
          }
          this.isShow();

      }
    }
</script>

<style scoped>

</style>
